package com.example;

import java.sql.*;

public class JDBCMain2 {
    /* 新增 */
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url ="jdbc:mysql://localhost:3306/java_web_study";
        String username = "root";
        String password = "123456";
        Connection connection = DriverManager
                .getConnection(url, username, password);
        Statement statement = connection.createStatement();
        // 新增的SQL语句
        String sql = "insert into t_user\n" +
                "    (username, password, sex, description, created)\n" +
                "values ('老六', '123456', 1, '介绍', '2024-11-26 14:40:05')";
//        ResultSet resultSet = statement.executeQuery();
        // 执行增删改都可以用executeUpdate()方法
        int i = statement.executeUpdate(sql);
        System.out.println(i); // i为1即成功，1为0即失败
        statement.close();
        connection.close();
    }
}
